package com.luntan.util.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.luntan.domain.TUser;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

/**
 *
 * 权限拦截器
 */
public class SecurityInterceptor extends MethodFilterInterceptor {

    @Override
    protected String doIntercept(ActionInvocation ai) throws Exception {

//        ActionContext context = ai.getInvocationContext();
//        Map<String, Object> session = context.getSession();
//        HttpServletRequest request = ServletActionContext.getRequest();
//        TUser user = (TUser) request.getSession().getAttribute("User");
//        Map<String,String> map = (Map<String,String>) request.getSession().getServletContext().getAttribute("UserInfoMap");
//        System.out.println("登录成功:"+user.getUserName()+"/"+request.getSession().getId());
//        if(!request.getSession().getId().equals(map.get(user.getUserName()))){
//            //同一个账号同一时间只能登录一次，不能同时登录多次
//            return "";
//        }
//        
//        ActionProxy proxy = ai.getProxy();//代理对象
//        String method = proxy.getMethod();//准备要执行的Action中的方法名
//        Integer methodIndex = Methods.getMethodIndex(method);
//        if (user == null && methodIndex != null) {
//            return "";
//        }
//
//        if (auth == false) {//跳转一个页提示
//            request.setAttribute("msg1", "您没有权限执行此操作");
//            return "auth1";
//        }
        return ai.invoke();//传达给下一个拦截器
    }
}
